using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using SMWJamecl.BusinessEntities;

namespace SMWJamecl.Repository.Mapping
{
    public class VehiculoMap : EntityTypeConfiguration<Vehiculo>
    {
        public VehiculoMap()
        {
            // Primary Key
            this.HasKey(t => t.Placa);

            // Properties
            this.Property(t => t.Placa)
                .IsRequired()
                .IsFixedLength()
                .HasMaxLength(7);

            this.Property(t => t.Color)
                .HasMaxLength(50);

            this.Property(t => t.Anio_Fabricacion)
                .IsFixedLength()
                .HasMaxLength(4);

            this.Property(t => t.NroMotor)
                .HasMaxLength(15);

            this.Property(t => t.NroSerie)
                .HasMaxLength(15);

            this.Property(t => t.NroChasis)
                .HasMaxLength(15);

            this.Property(t => t.Estado)
                .HasMaxLength(50);

            // Table & Column Mappings
            this.ToTable("Vehiculo");
            this.Property(t => t.Placa).HasColumnName("Placa");
            this.Property(t => t.Id_Version).HasColumnName("Id_Version");
            this.Property(t => t.Color).HasColumnName("Color");
            this.Property(t => t.Anio_Fabricacion).HasColumnName("Anio_Fabricacion");
            this.Property(t => t.NroMotor).HasColumnName("NroMotor");
            this.Property(t => t.NroSerie).HasColumnName("NroSerie");
            this.Property(t => t.NroChasis).HasColumnName("NroChasis");
            this.Property(t => t.NroAsientos).HasColumnName("NroAsientos");
            this.Property(t => t.Id_DetalleAccesorio).HasColumnName("Id_DetalleAccesorio");
            this.Property(t => t.Kilometraje).HasColumnName("Kilometraje");
            this.Property(t => t.Id_Combustible).HasColumnName("Id_Combustible");
            this.Property(t => t.Estado).HasColumnName("Estado");

            // Relationships
            this.HasOptional(t => t.Combustible)
                .WithMany(t => t.Vehiculoes)
                .HasForeignKey(d => d.Id_Combustible);
            this.HasOptional(t => t.Version)
                .WithMany(t => t.Vehiculoes)
                .HasForeignKey(d => d.Id_Version);

        }
    }
}
